package cn.ubeta.b2c.user.coupon;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.text.TextUtils;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import cn.ubeta.b2c.R;
import cn.ubeta.b2c.api.ApiUser;
import cn.ubeta.b2c.bean.CouponInfo;
import cn.ubeta.b2c.common.ListFragment;
import cn.ubeta.b2c.common.ListFragmentConfig;
import cn.ubeta.b2c.widget.recyclerview.BaseViewHolder;

/**
 * Created by denny on 16/9/6.
 */

public class CouponFragment extends ListFragment<CouponInfo> {

    private static final String ARG_TYPE = "coupon_type";

    private int mType;

    public static Fragment newInstance(int type) {
        CouponFragment fragment = new CouponFragment();
        Bundle args = new Bundle();
        args.putInt(ARG_TYPE, type);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        mType = getArguments().getInt(ARG_TYPE);
        super.onCreate(savedInstanceState);
    }

    @Override
    protected ListFragmentConfig getConfig() {
        return new ListFragmentConfig(R.layout.item_coupon);
    }

    @Override
    protected void bindItemView(BaseViewHolder helper, CouponInfo item) {
        // 商品图片
        SimpleDraweeView img = helper.getView(R.id.iv_product);
        // 商品标题
        String name = item.getTitle();
        if (!TextUtils.isEmpty(name)) {
            ((TextView) helper.getView(R.id.tv_name)).setText(name);
        }
    }

    @Override
    protected void loadData(int page) {
        ApiUser.getCoupon(mType, page, getNetworkCallback());
    }

}
